try:
    t = int(input())
    for t1 in range(t):
        n = int(input())
        cards = {}
        for n1 in range(n):
            temp = [int(item) for item in input().split()]
            for n2 in range(n):
                if temp[n2] in cards:
                    if cards[temp[n2]][0] == n1:
                        cards[temp[n2]][1] = n2
                else:
                    cards[temp[n2]] = [n1, n2]
        q = int(input())
        for i in range(q):
            x = int(input())
            if x in cards:
                print('%d %d' % (cards[x][0] + 1, cards[x][1] + 1))
            else:
                print(-1)
except ValueError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
